/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.haiberg.osgi.bundle.reportservice.factory;

import com.haiberg.osgi.bundle.reportservice.ReportRequestHandler;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;

/**
 *
 * @author gyue
 */
public class ReportRequestHandlerFactory implements ServiceFactory<ReportRequestHandler>{

    private int usageCounter = 0;

    @Override
    public ReportRequestHandler getService(Bundle bundle, ServiceRegistration<ReportRequestHandler> sr) {
        usageCounter++;
        System.out.println("create ReportRequestHandler");
        ReportRequestHandler requestHandler = null;
        try{
            requestHandler = new ReportRequestHandler();
            System.out.println(requestHandler);
        }catch(Exception e){
            e.printStackTrace();
        }
        return requestHandler;
    }

    @Override
    public void ungetService(Bundle bundle, ServiceRegistration<ReportRequestHandler> sr, ReportRequestHandler s) {
        usageCounter--;
        System.out.println("Number of bundles using ReportRequestHandler service " + usageCounter);
    }
}
